{include file="common/head"/}
<div class="layui-fluid"><div class="layui-card"><div class="layui-card-body">
<fieldset class="layui-elem-field layui-field-title">
        <legend>保险管理{:lang('list')}</legend>
    </fieldset>
    <blockquote class="layui-elem-quote">
        <a href="{:url('add')}" class="layui-btn layui-btn-sm">
            {:lang('add')}保险
        </a>
    </blockquote>
    <table class="layui-table" id="list" lay-filter="list"></table>
</div>
{include file="common/foot"/}
<script type="text/html" id="bom">
    {{d.bomlimit}}-{{d.toplimit}}
</script>
<script type="text/html" id="sort">
    <input name="{{d.id}}" data-id="{{d.id}}" class="list_order layui-input" value=" {{d.sort}}" size="10"/>
</script>
<script type="text/html" id="action">
    <a href="{:url('edit')}?id={{d.id}}" class="layui-btn layui-btn-xs">{:lang('edit')}</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">{:lang('del')}</a>
</script>


<script type="text/html" id="open">
    <input type="checkbox" name="open" value="{{d.id}}" lay-skin="switch" lay-text="开启|禁用" lay-filter="open" {{ d.open == 1 ? 'checked' : '' }}>
</script>



<script> 
    layui.use(['table','form'], function() {
        var table = layui.table, form=layui.form,$ = layui.jquery;
        table.render({
            id: 'user',
            elem: '#list',
            url: '{:url("index")}',
            method: 'post',
            cols: [[
                {field: 'id', title: '{:lang("id")}', width: 80, fixed: true, sort: true},
                {field: 'typename', title: '种类', width: 120,sort: true},
                {field: 'title', title: '保险', width: 120},
                {field: 'rate', title: '利率', width: 120},
                {field: 'sort',align: 'center',title: '{:lang("order")}', width: 120,templet:'#sort',sort: true},

                {field: 'open', title: '{:lang("status")}', width: 120,toolbar: '#open'},
                {title: '操作', width: 160, align: 'center', toolbar: '#action'}
            ]]
        });

        form.on('switch(open)', function(obj){
            loading =layer.load(1, {shade: [0.1,'#fff']});
            var id = this.value;
            var open = obj.elem.checked===true?1:0;
            $.post('{:url("open")}',{'id':id,'open':open},function (res) {
                layer.close(loading);

                if (res.status==1) {
                    tableIn.reload();
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                    return false;
                }
            })
        });        

        table.on('tool(list)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('您确定要删除该记录吗？', function(index){
                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post("{:url('del')}",{id:data.id},function(res){
                        layer.close(loading);
                        if(res.code==1){
                            layer.msg(res.msg,{time:1000,icon:1});
                            obj.del();
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
        });
        $('body').on('blur','.list_order',function() {
            var id = $(this).attr('data-id');
            var sort = $(this).val();
            $.post('{:url("order")}',{id:id,sort:sort},function(res){
                if(res.code==1){
                    layer.msg(res.msg,{time:1000,icon:1},function(){
                        location.href = res.url;
                    });
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                }
            })
        })
    });
</script>